package com.zzty.txj1.controller;


import com.zzty.txj1.entity.Question;
import com.zzty.txj1.entity.SelfExam;
import com.zzty.txj1.entity.TeamExam;
import com.zzty.txj1.entity.User;
import com.zzty.txj1.service.QuestionService;
import com.zzty.txj1.service.TodayExamService;
import com.zzty.txj1.service.TodayTeamExamService;
import com.zzty.txj1.util.SplitUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/todayTeamExam")
public class TodayTeamExamController {

    @Autowired
    QuestionService questionService;

    @Autowired
    TodayTeamExamService todayTeamExamService;

    @RequestMapping(value = "/checkHomework")
    public TeamExam checkHomework(TeamExam teamExam, HttpServletRequest request){
        User user=(User)request.getSession().getAttribute("user");
        teamExam.setClassId(user.getClazzid());
        System.out.println("11  "+teamExam.toString());
        TeamExam teamExam1=todayTeamExamService.checkHomework(teamExam);
        System.out.println("22  "+teamExam1);
        return  teamExam1;
    }

    @RequestMapping(value = "/getQuestionContent",method = RequestMethod.POST)
    public String getQuestionContent(TeamExam teamExam){
        String questionId=teamExam.getQuestionId();
        List<Integer> questionIds=new ArrayList<Integer>();
        SplitUtil splitUtil=new SplitUtil();
        questionIds=splitUtil.getSplit(questionId);
        String questions="";
        int i=1;
        for(Integer id:questionIds){
            Question question=new Question();
            question.setId(id);
            questions+="第"+i+"题："+questionService.getContentById(question)+"\n";
            i++;
        }
        return questions;
    }

}
